import os

from django.views import View

from Venue import Constants
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequired


class GoodsImageView(View):
    """ 商品图片信息 """

    @LoginRequired.Venue
    @Req.getJson
    def post(self, request):
        """ 上传 """
        id = request.POST.get('id')
        image = request.FILES.get("image")

        path = os.path.join(Constants.Goods_Image_Path, str(id))
        with open(path, "wb") as f:
            f.write(image.file.read())
        return Res.Json(Res.OK)
